package java3_16.Company;

public class Company {
    String name;
    String address;
    String phone;
    String range;
    int count = 0;//统计人数

    Employee[] emp = new Employee[10];

    public Company(String name, String address, String phone, String range) {
        this.name = name;
        this.address = address;
        this.phone = phone;
        this.range = range;
    }

    public void show() {
        System.out.println("公司名称：" + name + "\n" + "地址：" + address + "\n" + "公司电话：" + phone +
                "\n" + "公司经营范围：" + range);
    }

    //判断员工idCard是否重复
    public boolean checkRepeat(String newidCard) {
        for (int i = 0; i < count; i++) {
            if (emp[i].getIdCard().equals(newidCard)) {
                return false;//员工号码重复
            }
        }
        return true;
    }

    //加入新员工
    public boolean add(Employee a) {
        if (!checkRepeat(a.getIdCard()) || count >= emp.length) {
            System.out.println("无法加入新员工！");
            return false;
        }
        emp[count++] = a;
        return true;//加人成功
    }

    //输出员工信息
    public void showEmp() {
        for (int i = 0; i < count; i++) {
            if (emp[i] == null) {
                return;
            }
            System.out.println(emp[i].getIdCard() + "," + emp[i].getName() + "," + emp[i].getAge() + "," + emp[i].getSex()
                    + "," + emp[i].getPost() + "," + emp[i].getSalary());
            System.out.println();
        }
    }

    //辞退员工
    public void dismiss(String idCard) {
        for (int i = 0; i < emp.length; i++) {
            if (emp[i] == null) {
                System.out.println("您要辞退的员工不存在！");
                return;
            }
            if (idCard.equals(emp[i].getIdCard())) {
                if (i == count - 1) {
                    emp[i] = null;
                    System.out.println("辞退成功");
                    return;
                }
                for (int j = i + 1; j < count; j++) {
                    emp[j - 1] = emp[j];
                    if (j == count - 1) {
                        emp[j] = null;
                    }
                }
                System.out.println("辞退成功");
                return;
            }
        }
    }

    public int number() {
        int x = 0;
        for (int i = 0; i < count; i++) {
            if (emp[i] != null) {
                x++;
            }
        }
        return x;
    }
}
